package labox.innovation.gameserver.network.clientpackets;

import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.network.SystemMessageId;
import labox.innovation.gameserver.network.serverpackets.SystemMessage;

/**
 * @author ljsh
 * 更改队伍分配方式
 *
 */
public class RequestChangeDistribution extends L2GameClientPacket {
	private static final String _C_RequestChangePartyModeOfDistribution = "C RequestChangePartyModeOfDistribution";

	private int type;

	@Override
	public String getType() {

		return _C_RequestChangePartyModeOfDistribution;
	}

	@Override
	protected void readImpl() {
		type = readByte();
	}

	@Override
	protected void runImpl() {
		FuzePcInstance actor = getClient().getActiveChar();
		SystemMessage ms=null;
		if (actor == null) {
			return;
		}
		if (!actor.isInParty()) {
			ms=new SystemMessage(SystemMessageId.YOU_ARE_NOT_IN_THE_PARTY);
			actor.sendPacket(ms);
			return;
		}
		if (!actor.getParty().isLeader(actor)) {
			ms=new SystemMessage(SystemMessageId.YOU_CAN_NOT_CHANGE_PARTY_MODEL);
			actor.sendPacket(ms);
			return;
		}
		actor.getParty().setLootDistribution(type);
		String dis = null;
		if (type == 1) {
			dis = "随机分配";
		}
		if (type == 0) {
			dis = "自由分配";
		}
		for (FuzePcInstance temp : actor.getParty().getPartyMembers()) {
			if (temp.isOnline() == 1 ? true : false) {
				ms=new SystemMessage(SystemMessageId.PARTY_MODEL);
				ms.addString(dis);
				temp.sendPacket(ms);
			}
		}
	}

}
